package com.idanchuang.component.base;

import com.idanchuang.component.base.actuator.DcHealthWebEndpointResponseMapper;
import com.idanchuang.component.base.actuator.tomcat.TomcatHealthIndicatorAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.health.HealthEndpointProperties;
import org.springframework.boot.actuate.health.HealthStatusHttpMapper;
import org.springframework.boot.actuate.health.HealthWebEndpointResponseMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author yjy
 * Created at 2021/3/19 10:59 上午
 */
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass({HealthStatusHttpMapper.class, HealthEndpointProperties.class})
@Import(TomcatHealthIndicatorAutoConfiguration.class)
public class ComponentBaseHealthAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(name = "acgHealthWebEndpointResponseMapper")
    public HealthWebEndpointResponseMapper acgHealthWebEndpointResponseMapper(
            HealthStatusHttpMapper statusHttpMapper,
            HealthEndpointProperties properties) {
        return new DcHealthWebEndpointResponseMapper(statusHttpMapper,
                properties.getShowDetails(), properties.getRoles());
    }



}
